package com.wgchao.amc.repository.base;

import com.wgchao.amc.entity.base.SysBaseRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @作者  wgchao
 * @时间 2019-10-29 
 * @用途  
 */
@Repository
public interface SysBaseRoleRepository  extends JpaRepository<SysBaseRole, Long>, JpaSpecificationExecutor<SysBaseRole> {

    SysBaseRole findFirstByRoleNameAndAgencyCode(String roleName, String agencyCode);

    @Query("from SysBaseRole where id = ?1 and id in (select roleId from SysBaseGr " +
            "where  del =0 and groupId in (select groupId from SysBaseUg where userId = ?2 and del = 0))")
    SysBaseRole findRoleByUG(Long roleId, Long userId);

    List<SysBaseRole> findAllByAgencyCodeAndDelIsFalse(String agencyCode);
}
